package com.example.demo.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 标记为配置类
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 重写addInterceptors方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截
        registry.addInterceptor(new TokenInterceptor())
                // 配置拦截请求，拦截所有请求
                .addPathPatterns("/**")
                // 配置放行请求，放行login请求
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/logout");
    }
}
